<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class klien extends CI_Controller {

    function __construct() {
        parent::__construct();
        $this->load->model('m_klien');
        $this->load->helper('date');
    }

    function index() {
        $data['list'] = $this->m_klien->get_all_klien();
        $data['konten'] = 'v_klien';
        $this->load->view('theme', $data);
    }

    function tambah_klien() {
        $data['konten'] = 'v_klien_tambah';
        $this->load->view('theme', $data);
    }

    function fungsi_tambah_klien() {
        $data['nama_perusahaan'] = $this->input->post('nama_perusahaan');
        $data['kode_klien'] = $this->input->post('kode_klien');
        $data['alamat'] = $this->input->post('alamat');
        $data['contact_person'] = $this->input->post('contact_person');
        $data['notelp'] = $this->input->post('notelp');
        $data['informasi'] = $this->input->post('informasi');
        $res = $this->m_klien->insert_klien($data);
        if ($res) {
            header('location:' . base_url() . "klien/" . $this->index());
        }
    }

    function edit_klien() {
        $id = $this->uri->segment(3);
        $data['klien'] = $this->m_klien->get_by_id($id);
        $data['konten'] = 'v_klien_edit';
        $this->load->view('theme', $data);
    }

    function update_klien() {
        $data['nama_perusahaan'] = $_POST['nama_perusahaan'];
        $data['kode_klien'] = $_POST['kode_klien'];
        $data['alamat'] = $_POST['alamat'];
        $data['contact_person'] = $_POST['contact_person'];
        $data['notelp'] = $_POST['notelp'];
        $data['informasi'] = $_POST['informasi'];
        $res = $this->m_klien->update_klien($data, $_POST['id_klien']);
        if ($res) {
            header('location:' . base_url() . "klien/" . $this->index());
        }
    }

    function hapus_klien($id_klien) {
        $res = $this->m_klien->delete_klien($id_klien);
        if ($res) {
            header('location:' . base_url() . "klien/" . $this->index());
        }
    }

    function list_area($id_klien) {
        $data['list'] = $this->m_klien->get_list_area_by_id_klien($id_klien);
        $data['konten'] = 'v_klien_list_area';
        $this->load->view('theme', $data);
    }

    function tambah_list_area($id_klien) {
        $data['list'] = $this->m_klien->get_all_klien($id_klien);
        $data['konten'] = 'v_klien_list_area_tambah';
        $this->load->view('theme', $data);
    }

    function fungsi_tambah_list_area($id_klien) {
        //$data['list'] = $this->m_klien->get_list_area_by_id_klien($id_klien);
        $data['id_klien'] = $this->input->post('id_klien');
        $data['list_area'] = $this->input->post('list_area');
        $data['list_sub_area'] = $this->input->post('list_sub_area');
        $res = $this->m_klien->insert_list_area($data);
        if ($res) {
            header('location:' . base_url() . "klien/$id_klien" . $this->index());
        }
    }

    function edit_list_area() {
        $id = $this->uri->segment(3);
        $data['list'] = $this->m_klien->get_all_klien();
        $data['list_area'] = $this->m_klien->get_list_area_by_id($id);
        $data['konten'] = 'v_klien_list_area_edit';
        $this->load->view('theme', $data);
    }

    function update_list_area() {
        $data['id_klien'] = $_POST['id_klien'];
        $data['list_area'] = $_POST['list_area'];
        $data['list_sub_area'] = $_POST['list_sub_area'];
        $res = $this->m_klien->update_list_area($data, $_POST['id_list_area']);
        if ($res) {
            header('location:' . base_url() . "klien/" . $this->index());
        }
    }

    function hapus_list_area($id_list_area) {
        $res = $this->m_klien->delete_list_area($id_list_area);
        if ($res) {
            header('location:' . base_url() . "klien/" . $this->index());
        }
    }

    function checklist() {
        $data['konten'] = 'v_checklist';
        $this->load->view('theme', $data);
    }

    function tambah_checklist() {
        $data['konten'] = 'v_checklist_tambah';
        $this->load->view('theme', $data);
    }

    function fungsi_tambah_checklist() {
        $data['pertanyaan'] = $this->input->post('pertanyaan');
        $res = $this->m_klien->insert_checklist($data);
        if ($res) {
            header('location:' . base_url() . "klien/checklist" . $this->index());
        }
    }

    function edit_checklist() {
        $id = $this->uri->segment(3);
        $data['klien'] = $this->m_klien->get_checklist_by_id($id);
        $data['konten'] = 'v_checklist_edit';
        $this->load->view('theme', $data);
    }

    function update_checklist() {
        $data['pertanyaan'] = $_POST['pertanyaan'];
        $res = $this->m_klien->update_klien($data, $_POST['id_pertanyaan']);
        if ($res) {
            header('location:' . base_url() . "klien/checklist" . $this->index());
        }
    }

    function hapus_checklist($id_pertanyaan) {
        $res = $this->m_klien->delete_checklist($id_pertanyaan);
        if ($res) {
            header('location:' . base_url() . "klien/checklist" . $this->index());
        }
    }

}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */